<?php
include("include/config.inc.php");
$query1 = "DELETE FROM invoice 
            WHERE invoiceId = ".$_REQUEST['invoiceId'];
$result1= mysql_query($query1);
if(!$result1)
{
  echo "Delete Fail";
}
else
{
  $images = "DELETE FROM invoice 
             WHERE invoiceId = ".$_REQUEST['invoiceId'];
  $imagesRes= mysql_query($images);
  
  $selMoreDetailRecord = "SELECT contractId FROM invoice WHERE contractId = ".$_REQUEST['contractId']."";
  $selMoreDetailRecordRes = mysql_query($selMoreDetailRecord);
  $resultRes = mysql_num_rows($selMoreDetailRecordRes);
  if($resultRes == 0)
  {
    $deleteContract = "DELETE FROM contract 
                        WHERE contractId = ".$_REQUEST['contractId'];
    $deleteContractRes = mysql_query($deleteContract);                        
  }

  header("Location:invoiceDetail.php?contractId=".$_REQUEST['contractId']);
}
?>